package com.wuzheng.wisgo.sanitation.cloud.repository.builder.locate;

import com.wuzheng.wisgo.sanitation.cloud.enums.MapTypeEnum;
import com.wuzheng.wisgo.sanitation.cloud.model.locate.param.PositionVehicleParam;
import com.wuzheng.wisgo.sanitation.framework.util.StringUtils;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author：hibon
 * @date：Created in 2019/10/09
 * @description：构建sql
 * @modified By：
 * @version: 1.0
 */
public class PositionBuilder {

    /**
     * 构建查询定位车辆详细信息sql
     *
     * @param positionVehicleParam
     * @return
     */
    public String builderSelectPositionVehicleVoInfoSql(PositionVehicleParam positionVehicleParam) {
        return new SQL() {
            {
                SELECT("t1.veh_id AS vehId, t2.veh_code AS vehCode,t2.vch_fuel_type_id AS vehFuelType");
                SELECT("t2.veh_use_type_name AS useTypeName, t2.vch_picture_url AS imageUrl");
                SELECT("t3.t_address AS address, t1.rec_vch_direction AS direction");
                SELECT("t1.rec_veh_status AS vehicleStatus, t1.rec_veh_speed AS speed");
                SELECT("t1.rec_fuel_quantity||' L' AS fuelCapacity, t1.rec_soc||'%' AS socCapacity");
                SELECT("t1.rec_job_status AS operatingStatus, t1.rec_collection_time AS positionTime");
                FROM("t_receive_info_new AS t1");
                JOIN("ba_vehicle AS t2 ON t1.veh_id = t2.id");
                JOIN("t_map_base AS t3 ON t1.rec_latitude = t3.t_latitude AND t1.rec_longitude = t3.t_longitude");
                WHERE("t1.veh_id = #{vehId} AND t1.rec_vin = #{vinCode}");
                if (StringUtils.isBlank(positionVehicleParam.getMapMark())) {
                    WHERE("t3.t_map_type = '".concat(MapTypeEnum.GAODE.getTypeId()).concat("'"));
                } else {
                    WHERE("t3.t_map_type = #{mapMark}");
                }
            }
        }.toString();
    }
}
